<?php

require_once(dirname(__FILE__).'/../bin/bootstrap.php');
require_once(dirname(__FILE__).'/../../lib/query/uvmcSolrQuery.class.php');
$t = new lime_test(null, new lime_output_color());

// test: Query is created
$q = uvmcSolrQuery::create();
$t->is($q instanceof uvmcSolrQuery, true, "::create() returns an instance of uvmcSolrQuery");

// test: One term, adding it with andTerm
  $q->andTerm("symfony");
  $t->is($q->getqueryString(), "symfony", "One term, adding it with andTerm");
  $q->reset();
  
// test: One term, adding it with orTerm
  $q->orTerm("symfony");
  $t->is($q->getqueryString(), "symfony", "One term, adding it with orTerm");
  $q->reset();
  
// test: 2 terms joined with AND
  $q->andTerm('symfony')->andTerm('roulaize');
  $t->is($q->getQueryString(), "symfony AND roulaize", "2 terms joined with AND");
  $q->reset();

// test: 2 terms joined with OR
  $q->andTerm('symfony')->orTerm('cakePHP');
  $t->is($q->getQueryString(), "symfony OR cakePHP", "2 terms joined with OR");
  $q->reset();
  
// test: 2 terms with AND, 1 term with OR
  $q->andTerm('symfony')->andTerm('roulaize')->orTerm('cakePHP');
  $t->is($q->getQueryString(), "symfony AND roulaize OR cakePHP", "2 terms with AND, 1 term with OR");
  $q->reset();
  
// test: 1 field, 1 value, added with andField
  $q->andField('project', 'symfony 1.1');
  $t->is($q->getQueryString(), '(project:"symfony 1.1")', '1 field, 1 value, added with andField');
  $q->reset();
  
// test: 1 field, 1 value, added with orField 
  $q->orField('project', 'symfony 1.1');
  $t->is($q->getQueryString(), '(project:"symfony 1.1")', '1 field, 1 value, added with orField');
  $q->reset();
  
// test: 1 field, 2 values, added with orField 
  $q->andField('project', array('symfony 1.1', 'symfony 1.2'));
  $t->is($q->getQueryString(), '((project:"symfony 1.1") OR (project:"symfony 1.2"))', '1 field, 2 values, added with andField');
  $q->reset();

// test: 1 term, 1 field with 1 value
// 
  $q->andTerm('symfony')->andField('project', "symfony 1.1");
  $t->is($q->getQueryString(), 'symfony AND (project:"symfony 1.1")', '1 term, 1 field with 1 value');
  $q->reset();

// test: 1 term, 1 field with 2 values
  $q->andTerm('symfony')->andField('project', array("symfony 1.1", "symfony 1.2"));
  $t->is($q->getQueryString(), 'symfony AND ((project:"symfony 1.1") OR (project:"symfony 1.2"))', '1 term, 1 field with 2 value');
  $q->reset();
